package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 图片显示模式枚举
 */
public enum ImageDisplayMode implements BaseEnum {

    ORIGINAL("ORIGINAL", "原始尺寸"),
    FIT("FIT", "适应屏幕"),
    FILL("FILL", "填充屏幕"),
    CENTER("CENTER", "居中显示"),
    TILE("TILE", "平铺显示");

    private final String code;
    private final String description;

    ImageDisplayMode(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static ImageDisplayMode fromCode(String code) {
        for (ImageDisplayMode mode : values()) {
            if (mode.getCode().equals(code)) {
                return mode;
            }
        }
        throw new IllegalArgumentException("Unknown image display mode code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ImageDisplayMode fromDescription(String description) {
        for (ImageDisplayMode mode : values()) {
            if (mode.getDescription().equals(description)) {
                return mode;
            }
        }
        throw new IllegalArgumentException("Unknown image display mode description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}